package cc.orange.base;

import android.app.Activity;
import  android.app.Application;
import android.content.Context;
import android.os.Bundle;

import androidx.multidex.MultiDex;
import com.xuexiang.xupdate.XUpdate;
import com.xuexiang.xupdate.entity.UpdateError;
import com.xuexiang.xupdate.listener.OnUpdateFailureListener;
import com.zhy.http.okhttp.OkHttpUtils;

import org.litepal.LitePal;
import org.xutils.x;

import java.util.concurrent.TimeUnit;

import cc.orange.BuildConfig;
import cc.orange.entity.OKHttpUpdateHttpService;
import cc.orange.http.ApiService;
import cc.orange.utils.WxLogUtil;
import cc.orange.utils.ZXToastUtil;
import cc.orange.utils.emojis.AndroidEmoji;
import cc.orange.utils.emojis.RongUtils;
import demo.smart.access.xutlis.ZXApp;
import okhttp3.OkHttpClient;

import static com.xuexiang.xupdate.entity.UpdateError.ERROR.CHECK_NO_NEW_VERSION;

public class MyApp extends Application {

    private int appCount = 0;
    public static MyApp sInstance;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
        ZXApp.init(this,true);

        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

            }

            @Override
            public void onActivityStarted(Activity activity) {
                appCount++;
            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {
                appCount--;
            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {

            }
        });
    }

    /**
     * app是否在前台
     * @return true前台，false后台
     */
    public boolean isForeground(){
        return appCount > 0;
    }

    public static MyApp getApplication() {
        return  sInstance;
    }
}
